/*
 * BookkeepingMainFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package com.insigma.yanwenlong.bookkeeping.gui;

import java.sql.SQLException;
import java.util.List;

import javax.swing.table.DefaultTableModel;

import com.insigma.yanwenlong.bookkeeping.pojo.Account;
import com.insigma.yanwenlong.bookkeeping.service.AccountService;
import com.insigma.yanwenlong.bookkeeping.service.AccountServiceImpl;

/**
 *
 * @author  __USER__
 */
public class BookkeepingMainFrame extends javax.swing.JFrame {

	private AccountService accountService = new AccountServiceImpl();

	/** Creates new form BookkeepingMainFrame 
	 * @throws SQLException */
	public BookkeepingMainFrame() {
		//设置界面标题
		setTitle("主界面");
		//初始化界面
		initComponents();
		//居中显示
		setLocationRelativeTo(null);

		//读取数据
		try {
			List<Account> accounts = accountService.findaAccounts();
			DefaultTableModel defaultTableModel = (DefaultTableModel) tblAccountInfo
					.getModel();
			for (Account account : accounts) {
				defaultTableModel.addRow(new Object[] { account.getId(),
						account.getName(), account.getCurrAccount(),
						account.getCreateTime(), account.getUpdateTime(),
						account.getNote() });
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		btnAccount = new javax.swing.JButton();
		btnAccountList = new javax.swing.JButton();
		btnAnalysis = new javax.swing.JButton();
		btnType = new javax.swing.JButton();
		btnMember = new javax.swing.JButton();
		btnUpdatePassword = new javax.swing.JButton();
		jLabel1 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		tblAccountInfo = new javax.swing.JTable();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		btnAccount.setText("\u8d26\u6237\u7ba1\u7406");
		btnAccount.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnAccountActionPerformed(evt);
			}
		});

		btnAccountList.setText("\u8d26\u52a1\u7ba1\u7406");
		btnAccountList.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnAccountListActionPerformed(evt);
			}
		});

		btnAnalysis.setText("\u7edf\u8ba1\u5206\u6790");
		btnAnalysis.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnAnalysisActionPerformed(evt);
			}
		});

		btnType.setText("\u7c7b\u522b\u7ef4\u62a4");
		btnType.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnTypeActionPerformed(evt);
			}
		});

		btnMember.setText("\u6210\u5458\u7ba1\u7406");
		btnMember.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnMemberActionPerformed(evt);
			}
		});

		btnUpdatePassword.setText("\u5bc6\u7801\u4fee\u6539");
		btnUpdatePassword
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						btnUpdatePasswordActionPerformed(evt);
					}
				});

		jLabel1.setText("\u8d26\u6237\u6982\u89c8");

		tblAccountInfo.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] {

				},
				new String[] { "账户编号", "账户名称", "当前余额", "创建日期", "最新更新", "说明" }) {
			boolean[] canEdit = new boolean[] { false, false, false, false,
					false, false };

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		jScrollPane1.setViewportView(tblAccountInfo);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																585,
																Short.MAX_VALUE)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				btnAccount)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				btnAccountList)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				btnAnalysis)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				btnType)
																		.addGap(
																				27,
																				27,
																				27)
																		.addComponent(
																				btnMember)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				btnUpdatePassword))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				jLabel1)))
										.addContainerGap()));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																btnUpdatePassword,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																49,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnType,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																51,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnMember,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																50,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnAnalysis,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																51,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnAccountList,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																52,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnAccount,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																53,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(34, 34, 34)
										.addComponent(jLabel1)
										.addGap(18, 18, 18)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												263,
												javax.swing.GroupLayout.PREFERRED_SIZE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	//点击类别维护
	private void btnTypeActionPerformed(java.awt.event.ActionEvent evt) {
		new CategoryFrame().setVisible(true);
	}

	//点击成员管理
	private void btnMemberActionPerformed(java.awt.event.ActionEvent evt) {
		new MemberFrame().setVisible(true);
	}

	//点击密码修改
	private void btnUpdatePasswordActionPerformed(java.awt.event.ActionEvent evt) {
		new UpdatePassFrame().setVisible(true);
	}

	//点击统计分析
	private void btnAnalysisActionPerformed(java.awt.event.ActionEvent evt) {
		new CountDataFrame().setVisible(true);
	}

	//点击账务管理
	private void btnAccountListActionPerformed(java.awt.event.ActionEvent evt) {
		new DetailFrame().setVisible(true);
	}

	//点击账户管理
	private void btnAccountActionPerformed(java.awt.event.ActionEvent evt) {
		new AccountInfoFrame().setVisible(true);
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new BookkeepingMainFrame().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnAccount;
	private javax.swing.JButton btnAccountList;
	private javax.swing.JButton btnAnalysis;
	private javax.swing.JButton btnMember;
	private javax.swing.JButton btnType;
	private javax.swing.JButton btnUpdatePassword;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable tblAccountInfo;
	// End of variables declaration//GEN-END:variables

}